
local attrIconFiles = {
    ['力量'] = [[UI\Widgets\Console\Human\infocard-heroattributes-str.blp]],
    ['敏捷'] = [[UI\Widgets\Console\Human\infocard-heroattributes-agi.blp]],
    ['智力'] = [[UI\Widgets\Console\Human\infocard-heroattributes-int.blp]],
}

--三维按钮
class.attrs_button = extends(class.button)
{
    reload = true,
    main_tip = ' - |cffffff00主要属性|r|n - 每点提升|cff00ff001|r基础攻击',
    str_tip = ' - 每点提升生命上限和生命回复|n',
    agi_tip = ' - 每点提升基础护甲和攻击速度|n',
    int_tip = ' - 每点提升魔法上限和魔法回复|n',
    bottom_tip = '',
    new = function (parent,icon,x,y,w,h)
        local panel = class.attrs_button:builder 
        {
            parent = parent,
            x = x,
            y = y,
            w = w,
            h = h,
            normal_image = icon,
        }
        return panel
    end,

    init = function (self)
        class.button.init(self)
        self.panels = {}

        local names = {'力量','敏捷','智力'}
        local tips = {self}
        local color = {0xffff0000,0xff00ff00,0xff00ffff}
        for a,name in ipairs(names) do
            local panel = self:add_panel('',self.w,(a-1)*40 - 30,200,40)
            panel.name = name
            panel.title = panel:add_text(name..':',0,3,150,20,8,4)
            panel.text = panel:add_text('1000',5,20,150,20,8,4)
            panel.tip = ''
            
            panel.title:set_color(color[a])

            self.panels[a] = panel
        end
        
        return self
    end,

    update = function(self,unit)
        self:set_normal_image(attrIconFiles[unit.main_attribute or '力量'])

        for _,panel in ipairs(self.panels) do
            local key1 = ('基础%s'):format(panel.name)
            local key2 = ('额外%s'):format(panel.name)
            local key3 = ('基础%s%%'):format(panel.name)
            local base = math.floor(unit:get(key1))
            local ext = math.floor(unit:get(key2))
            local rate = math.floor(unit:get(key3))
            local text = ''
            base = format_number1(base)
            if ext > 0 then 
                text = ("%s + |cff00ff00%s|r"):format(base, format_number1(ext))
            elseif ext<0 then
                text = ("%s - |cffff0000%s|r"):format(base, format_number1(ext))
            else
                text = base
            end
            panel.text:set_text(text)
        end

    end,
    on_button_mouse_enter = function(self)
        local hero = ac.unit.localunit()
        if not hero then
            return
        end
        
        local info = {}
        local tips = {self.str_tip,self.agi_tip,self.int_tip}
        for a,panel in ipairs(self.panels) do
            local name = panel.name
            
            table.insert(info,name)
            if hero.main_attribute == name then 
                table.insert(info,self.main_tip)
            end
            table.insert(info,tips[a])
        end
        info[#info + 1] = self.bottom_tip
        local tip = table.concat(info,'|n')
        self:tooltip('属性数据',tip)
    end,
}
